#pragma once
#include "e2d/core/pch.h"
#include "PxPhysicsApi.h"

namespace e2d
{
	using namespace physx;

	struct  PxUtils
	{
		static physx::PxDefaultAllocator gAllocator;
		static physx::PxDefaultErrorCallback gErrorCallback;
		static physx::PxFoundation* gFoundation;
		static physx::PxPhysics* gPhysics;
		static physx::PxDefaultCpuDispatcher* gDispatcher;
		static physx::PxScene* gScene;

		static physx::PxTransform toPxTransform(const e2d::Transform& source)
		{
			physx::PxTransform transform;
			transform.q = toPxQuat(source.GetRotationQuat());
			transform.p = toPxVec3(source.m_Position);

			return transform;
		}
		static e2d::Transform toGlmTransform(const physx::PxTransform& source)
		{
			e2d::Transform transform;
			transform.SetRotation(toGlmQuat(source.q));
			transform.m_Position = toGlmVec3(source.p);
			transform.m_Scale = glm::vec3(1.0f);

			return transform;
		}
		static physx::PxQuat toPxQuat(const glm::quat& v)
		{
			return physx::PxQuat(v.x, v.y, v.z, v.w);
		}
		static physx::PxVec2 toPxVec2(const glm::vec2& v) {
			return { v.x, v.y };
		}
		static physx::PxVec3 toPxVec3(const glm::vec3& v) {
			return { v.x, v.y ,v.z };
		}
		static physx::PxVec4 toPxVec4(const glm::vec4& v) {
			return physx::PxVec4(v.x, v.y, v.z, v.w);
		}

		static glm::quat toGlmQuat(const physx::PxQuat& v)
		{
			return glm::quat(v.x, v.y, v.z, v.w);
		}
		static glm::vec2 toGlmVec2(const physx::PxVec2& v) {
			return { v.x, v.y };
		}
		static glm::vec3 toGlmVec3(const physx::PxVec3& v) {
			return { v.x, v.y ,v.z };
		}
		static glm::vec4 toGlmVec4(const physx::PxVec4& v) {
			return glm::vec4(v.x, v.y, v.z, v.w);
		}
	};
};

